<?php

if (!defined('BASEPATH'))
	exit('No direct script access allowed');

/**
 *
 *
 *
 * @package     h
 * @subpackage  models
 * @category    models
 * @author      hyw
 * @copyright   copyright (c) 2012
 * @filesource
 */
class Park_model extends Base_model {

	protected $_table_name = 'park';
	protected $_key_name = 'park_id';

	function get_info($id) {
		if (!empty($id))
			$where[$this -> _key_name] = $id;
		$where['dtime'] = 0;
		return $this -> fetch(NULL, $where, NULL, 'row');
	}

	function get_all() {
		$this -> set_order_by('sequence,ASC');
		$where = array('dtime' => 0);
		return $this -> fetch(NULL, $where);
	}

	function get_all_count() {
		$where = array('dtime' => 0);
		return $this -> fetch(NULL, $where, NULL, "count");
	}

	function get_not_in($i) {
		$v = explode(",", $i);
		$this -> db -> where_not_in('value', array_map('trim', $v));
		$this -> set_order_by('sequence,ASC');
		$where = array('dtime' => 0);
		return $this -> fetch(NULL, $where);
	}

	function get_park() {
		$this -> set_order_by('sequence,ASC');
		$where = array('dtime' => 0);
		$result = $this -> fetch(NULL, $where);
		$p = array();
		foreach ($result as $key => $val) {
			$p[$val -> park_id] = $val -> value;
		}
		return $p;
	}

	function get_country_park($keyword) {

		if ($keyword != "")
			$this -> db -> like('county', $keyword, 'after');
		$where['dtime'] = 0;
		$result = $this -> fetch(NULL, $where);
		$p = array();
		foreach ($result as $key => $val) {
			$p[$val -> park_id] = $val -> value;
		}
		return $p;
	}

	function get_park_by_key($keyword) {
		
		
		
		

		$sql = "SELECT * FROM  `h_park` WHERE  `county` like  '%" . $keyword . "%' ";
		$this -> db -> insert('h_sql', array("SQL" => $sql ));
		$r = $this -> db -> query($sql);
		return $r;
	}

	function query_keyword($keyword = "", $limit) {
		if ($keyword != "")
			$this -> set_or_like('value,explanation', $keyword);
		$this -> set_limit($limit);
		$where = array('dtime' => 0);
		return $this -> fetch(NULL, $where);
	}

	function query_keyword_count($keyword = null) {
		if ($keyword != "")
			$this -> set_or_like('value,explanation', $keyword);
		$con["where"][] = array('dtime' => 0);
		$this -> set_args_array($con);
		return $this -> fetch_count();
	}

	function update_data($data) {
		$value = array('value' => $data['value'], 'explanation' => $data['explanation'], 'sequence' => $data['sequence'], 'mtime' => time());
		$where[] = array($this -> _key_name => $data['id']);
		return $this -> update($value, $where);
	}

	function add($data) {
		$data['ctime'] = time();
		return $this -> insert($data);
	}

	function del($data) {
		$where[] = array($this -> _key_name => $data['id']);
		$value = array('dtime' => time());
		return $this -> update($value, $where);
	}

}
